<style>
.form-my div{float: left;margin-bottom: 10px;}
.form-my .label-my{height: 37px;line-height: 37px;width: 100px;}
.form-my .input-my{margin-right: 20px;}
.form-my .input-my input,.form-my .input-my textarea,.form-my .input-my select{width: 200px;}
.datepickerinput+button{display: none;}
</style>
<link rel="stylesheet" href="/public/assets/sysadmin/mylzp/css/jquery-ui.css">
<script type="text/javascript" src="/public/assets/sysadmin/mylzp/js/jquery-ui.js"></script>
<section class="vbox">
    <section class="scrollable padder">
        <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
            <li><a href="#"><i class="fa fa-home"></i> 订单管理中心</a></li>
            <li><a href="#">订单管理</a></li>
            <li class="active"><a href="#">已处理订单</a></li>
        </ul>
        <div class="m-b-md">
            <h3 class="m-b-none">已处理订单</h3>
        </div>
        <section class="panel panel-default">
            <div class="panel-body">
                <form class="form-horizontal form-bordered form-validate" method="post" id="edit" action="<?=$this->url('order/editP')?>" >
                <div class="form-my">
                    <div class="label-my">订单号：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" disabled="" name="orderId" value="<?=empty($re)?'':$re['orderId']?>">
                    </div>
                    <div class="label-my">客户姓名：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" name="data[name]" <?=!empty($re)&&$re['type']!=0?'disabled=""':''?> value="<?=empty($re)?'':$re['name']?>">
                    </div>
                    <div class="label-my">客户电话</div>
                    <div class="input-my">
                        <input type="text" class="form-control" name="data[mobile]" value="<?=empty($re)?'':$re['mobile']?>">
                    </div>
                    <div style="clear: both;"></div>
                </div>
                <div class="form-my">
                    <div class="label-my">房型/床型：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" disabled="" name="title" value="<?=empty($re)?'':$re['title'].'---'.$re['bed']?>">
                    </div>
                    <div class="label-my">房间数：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" name="data[countRoom]" value="<?=empty($re)?'':$re['countRoom']?>">
                    </div>
                    <div class="label-my">订单总价(元)：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" name="data[price]" value="<?=empty($re)?'':$re['price']?>">
                    </div>
                    <input type="hidden" name="total_price" id="total_price" value="<?=empty($re)?'':$re['price']?>" />
                    <div style="clear: both;"></div>
                </div>
                <div class="form-my">
                    <div class="label-my">入住时间：</div>
                    <div class="input-my">
                        <input type="text" class="form-control datepickerinput" <?=!empty($re)&&$re['status']==4?'disabled=""':'readonly="" style="background: #fff;cursor: default;"'?> name="data[startDate]" value="<?=empty($re)?'':date('Y-m-d',$re['startDate'])?>">
                    </div>
                    <div class="label-my">离店时间：</div>
                    <div class="input-my">
                        <input type="text" class="form-control datepickerinput" style="background: #fff;cursor: default;" readonly="" name="data[endDate]" value="<?=empty($re)?'':date('Y-m-d',$re['endDate'])?>">
                    </div>
                    <div class="label-my">最晚到店时间：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" <?=!empty($re)&&$re['status']==4?'disabled=""':''?> name="data[latestTime]" value="<?=empty($re)?'':$re['latestTime']?>">
                    </div>
                    <div style="clear: both;"></div>
                </div>
                
                <div class="form-my">
                    <div class="label-my">支付类型：</div>
                    <div class="input-my">
                        <select name="data[payType]" class="form-control" <?=!empty($re)&&$re['type']!=0?'disabled=""':''?>>
                            <option value="FG" <?=!empty($re)&&$re['payType']=="FG"?'selected':''?>>现付</option>
                            <option value="PP" <?=!empty($re)&&$re['payType']=="PP"?'selected':''?>>预付</option>
                            <option value="PKG" <?=!empty($re)&&$re['payType']=="PKG"?'selected':''?>>打包</option>
                        </select>
                    </div>
                    <div class="label-my">已付金额：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" name="data[paid]" value="<?=empty($re)?'':$re['paid']?>">
                    </div>
                    <div class="label-my">订单来源：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" disabled="" name="type" value="<?=!empty($re)&&!empty($re['typeName'])?$re['typeName']:'线下'?>">
                    </div>
                    <div style="clear: both;"></div>
                </div>
                
                <div class="form-my">
                    <div class="label-my">订单状态：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" disabled="" name="created" value="<?=empty($re)?'':$pmsconfigs['orderstatus'][$re['status']]?>">
                    </div>
                    <div class="label-my">下单时间：</div>
                    <div class="input-my">
                        <input type="text" class="form-control" disabled="" name="created" value="<?=empty($re)?'':date('Y-m-d H:i:s',$re['created'])?>">
                    </div>
                    <div class="label-my">订单备注：</div>
                    <div class="input-my">
                        <textarea class="form-control" name="data[remark]" id="remark"><?=empty($re)?'':$re['remark']?></textarea>
                    </div>
                    <div style="clear: both;"></div>
                </div>
                <input type="hidden" name="id" value="<?=empty($re)?'':$re['id']?>" />
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2" style="width: 100%;">
                        <button type="button" onclick="window.history.go(-1);" class="btn btn-default">返 回</button>
                        <button type="reset" class="btn btn-primary">重置订单</button>
                        <?
                        if(!empty($re)&&$re['status']==1){?>
                            <button type="button" onclick="submitorder(4)" class="btn btn-primary show_shadefrist">办理入住</button>
                            <?
                            if(!empty($re)&&$re['type']==0){?>
                                <button type="button" onclick="submitclick()" class="btn btn-primary show_shadefrist">修改订单</button>
                                <button type="button" onclick="submitorder(99)" class="btn btn-primary show_shadefrist">取消订单</button>
                            <?}
                            ?>
                        <?}elseif(!empty($re)&&$re['status']==4){?>
                            <button type="button" onclick="submitorder(3)" class="btn btn-primary show_shadefrist">办理退房</button>
                        <?}
                        ?>
                    </div>
                </div>
            </form>
            </div>
        </section>
    </section>
</section>
<a href="#" class="hide nav-off-screen-block" data-toggle="class:nav-off-screen" data-target="#nav"></a>

<script type="text/javascript">
//订单修改
change();
function submitclick(status){
    $('#edit').submit();
}

//时间插件
$(function(){
    $(".datepickerinput").datepicker({
        minDate: '',
        showMonthAfterYear: true,
        changeMonth: true,
        numberOfMonths: 1,
        showOn: "both",
    });
    $('.ui-datepicker-trigger').remove();
});

//修改房间数改变价格
function change(){
	$("input[name='data[countRoom]']").keyup(function(){
		var typeid='<?=!empty($re)?$re['roomId']:0?>';
	    var sta=$('input[name="data[startDate]"]').val();
	    var end=$('input[name="data[endDate]"]').val();
	    var countRoom=$('input[name="data[countRoom]"]').val();
	    $.ajax({
			type:'POST',
			url:'<?=$this->url("order/selectPrice")?>',
			data:'typeid='+typeid+'&sta='+sta+'&end='+end,
			dataType:'json',
			success:function(r){
				$('input[name="data[price]"]').val(Number(countRoom)*Number(r.html));
				$('input[name="total_price"]').val(Number(countRoom)*Number(r.html));
				change();
			},
	        error:function(){
	            pub_alert_error("ajax错误",2000);
	        }
		});
	});
}


//修改时间变动价格
$(".datepickerinput").change(function(){
    var typeid='<?=!empty($re)?$re['roomId']:0?>';
    var sta=$('input[name="data[startDate]"]').val();
    var end=$('input[name="data[endDate]"]').val();
    var countRoom=$('input[name="data[countRoom]"]').val();
    $.ajax({
		type:'POST',
		url:'<?=$this->url("order/selectPrice")?>',
		data:'typeid='+typeid+'&sta='+sta+'&end='+end,
		dataType:'json',
		success:function(r){
			$('input[name="data[price]"]').val(Number(countRoom)*Number(r.html));
			$('input[name="total_price"]').val(Number(countRoom)*Number(r.html));
			change();
		},
        error:function(){
            pub_alert_error("ajax错误",2000);
        }
	});
});

//修改状态**取消订单--办理入住--办理退房
function submitorder(status){
    var orderid='<?=empty($re)?0:$re['id']?>';
    var remark=$('#remark').val();
    if(status==99&&remark==''){
        pub_alert_error("请填写备注：取消的原因！",2000);
    }else{
        $.ajax({
    		type:'POST',
    		url:'<?=$this->url("order/ordersEdit")?>',
    		data:'id='+orderid+'&status='+status+'&remark='+remark,
    		dataType:'json',
    		success:function(r){
    		    if(r.state==0){
                    pub_alert_error(r.html,2000);
    		    }else if(r.state==1){
                    pub_alert_success(r.html,2000);
                    setTimeout(function(){window.history.go(-1);},2000);
    		    }
    		},
            error:function(){
                pub_alert_error("ajax错误",2000);
            }
    	});
    }
}
</script>